package com.method;

/*
要写注释哦!!!
*/
public class Demo12 {
    public static void main(String[] args) {
        int[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
        int[] resout = toNumber(arr);
        for (int i = 0; i < resout.length; i++) {
            System.out.print(resout[i]+" ");
        }

    }

    public static int[] toNumber(int[] arr) {
        int count = 0;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] % 2 == 0) {
                count++;
            }
        }
        int index = 0;
        int[] newArr = new int[count];
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] % 2 == 0) {
                newArr[index] = arr[i];
                index++;
            }
        }
        return newArr;
    }
}
